package com.demo.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.Pattern;

import org.springframework.context.annotation.Lazy;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * @Description TODO 讲师表
 * @author 姜皓泷
 * @changeLog 1. 创建 (2020年1月9日 下午4:57:32 [姜皓泷]) 2.
 */

@Entity
@Table(name = "lecturerdata")
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@NamedEntityGraph(name = "Lecturer.a", attributeNodes = {@NamedAttributeNode("dep")})
public class LecturerData implements Serializable {

	// TODO
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Integer id; // 主键

	@Column(name = "name")
	@Pattern(regexp = "^[\\u4e00-\\u9fa5]{2,}$", message = "姓名只能是中文")
	private String name; // 姓名

	@Column(name = "headimg")
	@Pattern(regexp = "^[\\s ?\\S]{20,}$", message = "必须要有头像")
	private String headimg; // 头像(存文件名)

	@Column(name = "department")
	private Integer department; // 头衔换成部门

	@Column(name = "source")
	private String source; // 来源

	@Column(name = "description")
	@Pattern(regexp = "\\S{2,}", message = "自我介绍必须要有的")
	private String description; // 个人说明

	@Column(name = "lable")
	private String lable; // 自定义讲师标签

	@Column(name = "creator")
	private Integer creator; // 创建人编号

	@Temporal(TemporalType.DATE) // 列如果是date类型，这里就必须要指定DATE；列如果是时间戳类型，这里就必须要指定TIMESTAMP类型
	@JsonFormat(pattern = "yyyy年MM月dd HH:mm:ss", timezone = "GMT+8") // 前端拿到的时间格式化
	@Column(name = "updateTime")
	private Date updateTime; // 修改时间

	@Temporal(TemporalType.DATE) // 列如果是date类型，这里就必须要指定DATE；列如果是时间戳类型，这里就必须要指定TIMESTAMP类型
	@JsonFormat(pattern = "yyyy年MM月dd HH:mm:ss", timezone = "GMT+8") // 前端拿到的时间格式化
	@Column(name = "creatTime")
	private Date creatTime; // 创建时间

	/**
	 * 因为配置了讲师的关联部门，查每个讲师，会去查所属部门
	 */
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "department", insertable = false, updatable = false)
	private Department dep;

	//@OneToMany(fetch = FetchType.LAZY, mappedBy = "lecturer")
	//Set<CourseWare> courseWares;

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the headimg
	 */
	public String getHeadimg() {
		return headimg;
	}

	/**
	 * @param headimg the headimg to set
	 */
	public void setHeadimg(String headimg) {
		this.headimg = headimg;
	}



	/**
	 * @return the dep
	 */
	public Department getDep() {
		return dep;
	}

	/**
	 * @param dep the dep to set
	 */
	public void setDep(Department dep) {
		this.dep = dep;
	}

	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the lable
	 */
	public String getLable() {
		return lable;
	}

	/**
	 * @param lable the lable to set
	 */
	public void setLable(String lable) {
		this.lable = lable;
	}

	/**
	 * @return the creator
	 */
	public Integer getCreator() {
		return creator;
	}

	/**
	 * @param creator the creator to set
	 */
	public void setCreator(Integer creator) {
		this.creator = creator;
	}

	/**
	 * @return the updateTime
	 */
	public Date getUpdateTime() {
		return updateTime;
	}

	/**
	 * @param updateTime the updateTime to set
	 */
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	/**
	 * @return the creatTime
	 */
	public Date getCreatTime() {
		return creatTime;
	}

	/**
	 * @param creatTime the creatTime to set
	 */
	public void setCreatTime(Date creatTime) {
		this.creatTime = creatTime;
	}


	
	public LecturerData() {
	}
	

	
	public Integer getDepartment() {
		return department;
	}

	public void setDepartment(Integer department) {
		this.department = department;
	}

//	public Set<CourseWare> getCourseWares() {
//		return courseWares;
//	}
//
//	public void setCourseWares(Set<CourseWare> courseWares) {
//		this.courseWares = courseWares;
//	}

	public LecturerData(Integer id, String name) {
		this.id=id;
		this.name = name;
	}
	
	public LecturerData(@Pattern(regexp = "^[\\u4e00-\\u9fa5]{2,}$", message = "姓名只能是中文") String name) {
		this.name = name;
	}
}
